
import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

class XinHeColor extends Color {
  static int _getColorFromHex(String hexColor) {
    hexColor = hexColor.toUpperCase().replaceAll("#", "");
    hexColor = hexColor.replaceAll('0X', '');
    if (hexColor.length == 6) {
      hexColor = "FF$hexColor";
    }
    return int.parse(hexColor, radix: 16);
  }

  XinHeColor(final String hexColor) : super(_getColorFromHex(hexColor));
}


abstract class XinHeStyle {

  static Color  mainGreenColor = XinHeColor('#30E9E9');

  ///默认背景色
  static Color  defaultBgColor = XinHeColor('#F3F8F9');


  static Color mainBalckFontColor = XinHeColor('#222222');

  static Color black333FontColor = XinHeColor('#333333');

  static Color lineColor = XinHeColor('#E7EEEF');

  /// 上一次所使用的状态栏字体颜色 用于返回页面时重设
  static SystemUiOverlayStyle? lastStyle;




  /// 设置设备状态栏字体颜色
  static void setSystemUIStyle({bool isLight = true}){
    SystemChrome.setSystemUIOverlayStyle(
        isLight?SystemUiOverlayStyle.light:SystemUiOverlayStyle.dark
    );
  }

  /// 设置状态栏颜色
  ///
  /// @isLight - 是否白色系
  ///
  /// @color - 背景色
  ///
  /// @isRootStyle - 是否标记样式
  static void setSystemBackgroundStyle({
    bool isLight = true,
    Color color = Colors.transparent,
    bool isRootStyle = false,
  }){
    if(isRootStyle){
      lastStyle = SystemUiOverlayStyle(
        statusBarColor: color,        //状态栏背景颜色
        statusBarIconBrightness: isLight ? Brightness.light:Brightness.dark,  // dark:一般显示黑色   light：一般显示白色
      );
      print('当前标记的颜色=>${lastStyle?.statusBarIconBrightness.toString()}');
    }
    SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
      statusBarColor: color,        //状态栏背景颜色
      statusBarIconBrightness: isLight ? Brightness.light:Brightness.dark,  // dark:一般显示黑色   light：一般显示白色
    )
    );
  }

}